<template>
    <div>
        <table class="table">
            <tbody class="table">
                <tr>
                    <td><span style="color: red;">*</span>标题</td>
                    <td>
                        <input type="text" v-model="data.title">
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>内容</td>
                    <td>
                        <textarea v-model="data.content"></textarea>
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>发布时间</td>
                    <td>
                        <input type="date" v-model="data.publishTime">
                    </td>
                </tr>
                <tr>
                    <td>状态</td>
                    <td>
                        <input type="radio" :value="true" name="s1" v-model="data.status">启用
                        <input type="radio" :value="false" name="s1" v-model="data.status">禁用
                    </td>
                </tr>
                <tr>
                    <td><span style="color: red;">*</span>类型</td>
                    <td>
                        <select v-model="data.tid">
                            <option :value="0">=请选择=</option>
                            <option v-for="x in showdata" :value="x.tid">{{x.tname}}</option>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td></td>
                    <td>
                        <input type="button" value="添加" @click="add">
                    </td>
                </tr>
            </tbody>
        </table>
    </div>
</template>

<script setup lang="ts">
import axios from 'axios';
import { ref,onMounted } from 'vue';


onMounted(() => {
    showdd();
})
const showdata=ref([{
     "tid": 0,
    "tname": ""
}])

const showdd=()=>{
    axios.get("https://localhost:7194/api/Anno/GetTypes").then(res=>{
        showdata.value=res.data;
    })
}

const data=ref({
"aid": 0,
  "title": "",
  "content": "",
  "publishTime": "",
  "status": true,
  "tid": 0
})
const add=()=>{
    if(data.value.title==""){
        alert("标题不能为空");
        return;
    }
    var s=/^[\u4e00-\u9fa5]{0,}$/
    if(!s.test(data.value.title)){
        alert("标题必须为汉字");
        return;
    }
    if(data.value.content==""){
        alert("内容不能为空");
        return;
    }
    if(data.value.publishTime==""){
        alert("时间不能为空");
        return;
    }
    if(data.value.tid==0){
        alert("类型必须选择");
        return;
    }
    axios.post("https://localhost:7194/api/Anno/Add",data.value).then(res=>{
        if(res.data>0){
            alert("添加成功")
        }else{
            alert("添加失败");
        }
    })
}

</script>

<style scoped>

</style>